package com.vpen.account.demo.controller.pub;

import com.vpen.account.demo.utils.RsaUtils;
import com.vpen.clib.result.CResult;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.vpen.clib.result.CResult.success;

/**
 * 描述
 *
 * @author 韦鹏
 * @date 2022/7/19 14:51
 */


@RestController
@RequestMapping("${api.account.public-url}/key")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class RsaKeyController {
    /**
     * 获取公钥
     */
    @GetMapping
    public CResult<String> getRsaPubKey() {
        return success(RsaUtils.getRsaPubKey());
    }

    /**
     * 加密
     */
    @PostMapping
    public CResult<String> encodePassword(@RequestParam String password) {
        return success(RsaUtils.encryptStr(password));
    }
}
